Weโre gonna look at Instacart data:
library(tidyverse)
library(p8105.datasets)
library(plotly)
data("instacart")
instacart =
instacart %>%
as_tibble(instacart) %>%
select(order_hour_of_day, aisle, department) %>%
filter(department %in% c("produce","dairy eggs"))
This is a barchart that shows the number of items ordered in each aisle from Produce or Dairy/Eggs departments (aisles are ordered by ascending number of items).
instacart %>%
count(aisle, department) %>%
mutate(aisle = fct_reorder(aisle, n)) %>%
plot_ly(x = ~aisle, y = ~n, color = ~department, type = "bar", colors = "viridis")
This is a barchart that shows the distribution of order time in hours for each aisle from Produce or Dairy/Eggs departments (aisles are ordered by ascending median order time).
instacart %>%
mutate(aisle = fct_reorder(aisle, order_hour_of_day)) %>%
plot_ly(x = ~aisle, y = ~order_hour_of_day, color = ~department, type = "box", colors = "viridis")